package student.action;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.util.DB;

import edu.student.models.*;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class SyllabusPage extends ActionSupport{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String subjectName;
	private String subjectCode;
	
	private String chapterName;
	private ArrayList<Syllabus> syllabus;
	private String username="";
	private List<News> news;
	private List<Announcements> announcements;
	private String image="";
	private Timestamp lastLogin;
	private String userid="";

	public List<Announcements> getAnnouncements() {
			return announcements;
		}

		public void setAnnouncements(List<Announcements> announcements) {
			this.announcements = announcements;
		}

		public List<News> getNews() {
			return news;
		}

		public void setNews(List<News> news) {
			this.news = news;
		}
		public String getUsername() {
			return username;
		}

		public void setUsername(String username) {
			this.username = username;
		}
		

		public String getImage() {
			return image;
		}

		public void setImage(String image) {
			this.image = image;
		}
		public Timestamp getLastLogin() {
			return lastLogin;
		}

		public void setLastLogin(Timestamp lastLogin) {
			this.lastLogin = lastLogin;
		}
		
		public String getUserid() {
			return userid;
		}

		public void setUserid(String userid) {
			this.userid = userid;
		}	
	public String execute(){
		Map<String, Object> session = ActionContext.getContext().getSession();
		User user = (User) session.get("user");
		if (user == null) {
			user = new User();
		}
		userid=user.getRollNor();
		username=user.getUsername();
		image=user.getImage();
		lastLogin=user.getLastLogin();
		news = News.getNews(" where ui.roll_No='"+userid+"' ");
		announcements=Announcements.getAnnouncements(" where ui.roll_No='"+userid+"' ");
		syllabus = Syllabus.findSyllabus(subjectCode);
		if(username.equalsIgnoreCase("admin"))
			return "adminSuccess";
		else
		    return "success";
	}
	
	public String getSubjectName() {
		return subjectName;
	}
	public void setSubjectName(String subjectName) {
		this.subjectName = subjectName;
	}
	public String getSubjectCode() {
		return subjectCode;
	}
	public void setSubjectCode(String subjectCode) {
		this.subjectCode = subjectCode;
	}
	
	public String getChapterName() {
		return chapterName;
	}
	public void setChapterName(String chapterName) {
		this.chapterName = chapterName;
	}
	public ArrayList<Syllabus> getSyllabus() {
		return syllabus;
	}
	public void setSyllabus(ArrayList<Syllabus> syllabus) {
		this.syllabus = syllabus;
	}
	
	
}
